package com.assist.service.impl;

import java.util.List;

import org.hibernate.Session;

import com.assist.dao.IActivityDAO;
import com.assist.dao.impl.ActivityDAOImpl;
import com.assist.model.Activity;
import com.assist.model.Category;
import com.assist.service.IActivityService;
import com.assist.util.HibernateUtil;

public class ActivityServiceImpl implements IActivityService{

	IActivityDAO activityDAO = new ActivityDAOImpl();

	@Override
	public boolean saveOrUpdateActivity(Activity activity) {
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();		
			activityDAO.saveOrUpdateActivity(activity);
			session.getTransaction().commit();
			return true;
		} catch (Exception e) {
			return false;
		}
	
	}

	@Override
	public List<Activity> getActivitiesByUserName(String userName) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
        List<Activity> activities = activityDAO.getActivitiesByUserName(userName);
		session.getTransaction().commit();		
		return activities;
	}

}
